package Server.Database;

import java.sql.SQLException;
import java.util.ArrayList;

/**
 *
 * @author Paulius Dambrauskas
 */
public class PhraseRegister {

    private Database db;

    public PhraseRegister(Database db) {
        this.db = db;
    }

    public void addPhraze(String phraze) throws SQLException {
        db.statement.executeUpdate("INSERT INTO filters (Phraze) VALUES ('" + phraze + "')");
    }

    public void deletePhraze(String phraze) throws SQLException {
        db.statement.executeUpdate("DELETE FROM filters WHERE Phraze = '" + phraze + "'");
    }

    public ArrayList<String> getAllPhrazes() throws SQLException {
        ArrayList<String> result = new ArrayList<String>();

        db.resultSet = db.statement.executeQuery("SELECT Phraze FROM filters");

        while (db.resultSet.next()) {
            result.add(db.resultSet.getString(1));
        }

        return result;
    }

    public ArrayList<String> getPhrazes() throws SQLException {
        ArrayList<String> filters = new ArrayList<String>();
        db.resultSet = db.statement.executeQuery("SELECT Phraze FROM filters");

        while (db.resultSet.next()) {
            filters.add(db.resultSet.getString(1));
        }
        return filters;
    }
}
